<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>思途CMS{$coreVersion}</title>
    {template 'stourtravel/public/public_js'}
    {Common::getCss('style.css,base.css,base_new.css')}
    {php echo Common::getScript("product_add.js,choose.js,imageup.js,jquery.buttonbox.js"); }
    <style>
        .cfg-header-bar{
            background: #ffffff;
        }
        .save-btn-con{
            position: fixed;
            bottom: 0;
            left: 50%;
            margin-left: -64px;
        }
        .product-add-div{
            height: 530px;
            overflow-y: scroll;
        }
        .radio-label{
            width: 100%;
            height: 100%;
            display: inline-block;
        }
    </style>
</head>
<body style=" overflow: hidden" right_padding=b9TX4t >
<div class="s-main">
    <div class="content-rt-td">
        <div class="cfg-header-bar">
            <div class="cfg-header-tab ad-type-con">
                <span class="item on" data-type="1" id="column_product" onclick="Product.switchTabs(this,'product')">跳转产品</span>
                <span class="item" data-type="2" id="column_uni_page" onclick="Product.switchTabs(this,'uni_page')">跳转UNI页面</span>
                <span class="item " data-type="3" id="column_custom_link" onclick="Product.switchTabs(this,'custom_link')">跳转自定义链接</span>
                <span class="item" data-type="4" id="column_third_mini" onclick="Product.switchTabs(this,'third_mini')">跳转三方小程序</span>
            </div>
        </div>
        <div class="clear clearfix">
            <div id="content_product" class="product-add-div content-show">
                <span class="select-box w150 mt-5 fl">
                    <select onchange="changeProductSelect(this)" class="select">
                        {loop $models $m}
                        <option value="{$m['id']}"> {$m['modulename']}</option>
                        {/loop}
                    </select>
                </span>
                <div class="cfg-header-search">
                    <input type="text" value="" id="searchkey" placeholder="产品标题" class="search-text">
                    <a href="javascript:;" class="search-btn" id="btn_search" onclick="CHOOSE.searchKeyword()">搜索</a>
                </div>
                <div id="product_list" style="line-height: 20px;"></div>
            </div>
            <div id="content_uni_page" class="product-add-div content-hide">
                <table class="table table-border table-bordered">
                    <tbody>
                    <tr>
                        <th class="text-c" width="50">所属模块</th>
                        <th class="text-c" width="50">页面标题</th>
                        <!--                        <th class="text-c" width="150">页面描述</th>-->
                        <th class="text-c" width="150">页面路径</th>
                        <th class="text-c" width="50">选择</th>
                    </tr>
                    {loop $xcx_page $pv}
                    {loop $pv['page'] $cv}
                    {if $cv['title'] != '详情页'}
                    <tr class="tb-item"  data-id="42">
                        <td class="text-c">{$pv['title']}</td>
                        <td class="text-c">{$cv['title']}</td>
                        <!--                        <td class="text-c">{$cv['dis']}</td>-->
                        <td class="text-c">{$cv['path']}</td>
                        <td class="text-c">
                            <label class="radio-label">
                                <input value="{$cv['path']}" data-subname="{$pv['subname']}" data-typeid="{$pv['typeid']}" data-title="{$cv['title']}" data-model="{$pv['title']}" name="uniPagePath" type="radio" />
                            </label>
                        </td>
                    </tr>
                    {/if}
                    {/loop}
                    {/loop}
                    </tbody>
                </table>
            </div>
            <div id="content_custom_link" class="product-add-div content-hide">
                <ul class="info-item-block">
                    <li>
                        <span class="item-hd">链接类型{Common::get_help_icon('uniapp_page_other_url_type')}：</span>
                        <div class="item-bd">
                            <label class="radio-label w100"><input type="radio" checked="" name="other_url_type" value="0">本站链接</label>
                            <label class="radio-label w100"><input type="radio" name="other_url_type" value="1">外站链接</label>
                            {if $mode==2}
                            <label class="radio-label w100"><input type="radio" name="other_url_type" value="2">电话</label>
                            <label class="radio-label w100"><input type="radio" name="other_url_type" value="3">企业微信</label>
                            {/if}

                            <br/><span class="item-text c-999">本站链接和外站链接区别请点击查看链接类型帮助{Common::get_help_icon('uniapp_page_other_url_type')}</span>
                        </div>
                    </li>
                    <li id="link_url">
                        <span class="item-hd">链接地址{Common::get_help_icon('nav_custom_link')}：</span>
                        <div class="item-bd">
                            <input type="text" name="link_url" data-required="true" class="input-text w300" value="" placeholder="请输入外部链接地址"/>
                        </div>
                    </li>
                    <li id="is_nested" style="display: none">
                        <span class="item-hd">webview(外部)：</span>
                        <div class="item-bd">
                            <label class="radio-label w100"><input type="radio" checked="" name="is_nested" value="1">开启</label>
                            <label class="radio-label w100"><input type="radio" name="is_nested" value="0">关闭</label>
                        </div>
                    </li>
                </ul>
            </div>
            <div id="content_third_mini" class="product-add-div content-hide">
                <ul class="info-item-block">
                    <li>
                        <span class="item-hd">小程序AppId{Common::get_help_icon('uniapp_page_third_appid')}：</span>
                        <div class="item-bd">
                            <input type="text" name="third_appid" data-required="true" class="input-text w300" value="" placeholder="请输入要打开的小程序APPID"/>
                            <span class="item-text c-999">*三方小程序广告位目前只支持小程序端进行跳转</span>
                        </div>
                    </li>
                    <li>
                        <span class="item-hd">小程序路径{Common::get_help_icon('uniapp_page_third_path')}：</span>
                        <div class="item-bd">
                            <input type="text" name="third_path" data-required="true" class="input-text w300" value="" placeholder="请输入小程序路径"/>
                            <span class="item-text c-999">*小程路径由跳转小程序方进行提供，获取<a style="color: #43aee4" href="http://www.stourweb.com/help/show/1196.html" target="_blank">路径方式</a></span>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <div class="clearfix text-c save-btn-con">
        <a href="javascript:;" class="btn btn-default radius c-999 mr-10 refuse" id="refuse-btn">取消</a>
        <a href="javascript:;" class="btn btn-primary radius" id="confirm-btn">确定</a>
    </div>
</div>
</body>
<script type="text/javascript">
var navid = "{$navid}";
//关联产品列表
Ext.onReady(
    function () {

        Ext.tip.QuickTipManager.init();
        //产品store
        window.product_store = Ext.create('Ext.data.Store', {
            fields: [
                'id',
                'title',
                'bh',
                'typename',
                'typeid',
                'litpic'
            ],
            proxy: {
                type: 'ajax',
                extraParams: {cid: $('#couponid').val()},
                api: {
                    read: SITEURL+'uniapp/get_product/action/read/'  //读取数据的URL
                },
                reader: {
                    type: 'json',   //获取数据的格式
                    root: 'lists',
                    totalProperty: 'total'
                }
            },
            remoteSort: true,
            pageSize: 12,
            autoLoad: true,
            listeners: {
                load: function (store, records, successful, eOpts) {
                    if(!successful){
                        ST.Util.showMsg("{__('norightmsg')}",5,1000);
                    }
                    var pageHtml = ST.Util.page(store.pageSize, store.currentPage, store.getTotalCount(), 10);
                    $("#line_page").html(pageHtml);
                    window.product_grid.doLayout();

                    $(".pageContainer .pagePart a").click(function () {
                        var page = $(this).attr('page');
                        product_store.loadPage(page);
                    });
                }
            }
        });

        //产品列表
        window.product_grid = Ext.create('Ext.grid.Panel', {
            store: product_store,
            renderTo: 'product_list',
            border: 0,
            width: "894px",
            height: "494px",
            bodyBorder: true,
            bodyStyle: 'border-width:0px',
            scroll:'vertical', //只要垂直滚动条
            bbar: Ext.create('Ext.toolbar.Toolbar', {
                store: product_store,  //这个和grid用的store一样
                displayInfo: true,
                emptyMsg: "",
                items: [
                    {
                        xtype:'panel',
                        id:'listPagePanel',
                        html:'<div id="line_page"></div>'
                    },
                    {
                        xtype: 'combo',
                        fieldLabel: '每页显示数量',
                        width: 170,
                        labelAlign: 'right',
                        forceSelection: true,
                        value: 12,
                        store: {fields: ['num'], data: [
                            {num: 12},
                            {num: 24},
                            {num: 48}
                        ]},
                        displayField: 'num',
                        valueField: 'num',
                        listeners:{
                            select:CHOOSE.changeNum
                        }
                    }
                ],
                listeners: {
                    single: true,
                    render: function (bar) {
                        var items = this.items;
                        bar.insert(0, Ext.create('Ext.panel.Panel', {border: 0, html: '<div class="panel_bar"></div>'}));
                        bar.insert(1, Ext.create('Ext.toolbar.Fill'));
                    }
                }
            }),
            columns: [
                {
                    text: '产品编号',
                    width: '20%',
                    dataIndex: 'bh',
                    align: 'left',
                    border: 0,
                    sortable: false,
                    menuDisabled:true,
                    renderer: function (value, metadata, record) {
                        return value;
                    }
                },
                {
                    text: '产品类型',
                    width: '20%',
                    dataIndex: 'typename',
                    align: 'center',
                    border: 0,
                    sortable: false,
                    menuDisabled:true,
                    renderer: function (value, metadata, record) {
                        return value;
                    }
                },
                {
                    text: '产品名称',
                    width: '40%',
                    dataIndex: 'title',
                    align: 'center',
                    border: 0,
                    sortable: false,
                    menuDisabled:true,
                    renderer: function (value, metadata, record) {
                        return value;
                    }
                },
                {
                    text: '选择',
                    width: '20%',
                    align: 'center',
                    border: 0,
                    dataIndex: 'id',
                    sortable: false,
                    menuDisabled:true,
                    renderer: function (value, metadata, record) {
                        var id = record.get('id');
                        var title = record.get('title');
                        return '<input type="radio" class="product_check" name="uni_product" style="cursor:pointer" data-name="'+title+'" value="'+id+'">';
                    }
                }
            ]
        });
    });

// 切换产品类型
function changeProductSelect(ele)
{
    var typeid=$(ele).val();
    window.product_store.getProxy().setExtraParam('typeid',typeid);
    window.product_store.loadPage(1);
}


$(function () {
    //关闭当前窗口
    $(document).on('click', '#refuse-btn', function () {
        ST.Util.closeBox();
    });
    // 监听自定义链接输入
    $("input[name='other_url_type']").on('change', function (){
        setLinkUrl();
    });
    $("input[name='link_url']").on('blur', function (){
        setLinkUrl();
    });
    // 优化输入的自定义链接
    function setLinkUrl(){
        var linkType = $("input[name='other_url_type']:checked").val();
        if(linkType === '0'){
            var linkUrl = decodeURI($.trim($("input[name='link_url']").val()));
            if(linkUrl){
                // 检查是否包含'h5/#'
                var len = linkUrl.indexOf("h5/#");
                if(len > 0){
                    // 截取字符串
                    linkUrl = linkUrl.slice(len+4);
                }else{
                    // 检查字符串包含'.html?'
                    if(linkUrl.indexOf('.html?')){
                        linkUrl = linkUrl.replace('.html?', '?');
                        // 检查开头是否包含 '/'
                        if(linkUrl.slice(0,1) !== '/'){
                            linkUrl = '/'+linkUrl;
                        }
                    }
                }
                $("input[name='link_url']").val(linkUrl);
            }
            $('#is_nested').hide();
            $('#link_url').show();
        }else if(linkType === '1'){
            $('#is_nested').show();
            $('#link_url').show();
        }else if(linkType === '2'){//电话
            $('#link_url').hide();
            $('#is_nested').hide();
        }else if(linkType === '3'){ //企业微信
            $('#link_url').hide();
            $('#is_nested').hide();
        }else{
            $('#link_url').show();
        }

    }
    // 保存数据
    $(document).on('click', '#confirm-btn', function () {
        // 判断要添加的广告类型
        var adType = $(".ad-type-con .on").attr('data-type');
        var res = {
            adType: adType,
            data : ''
        };
        if(adType === '1'){
            // 产品
            var productObj = $("input[name='uni_product']:checked");
            var productList = [];
            $.each(productObj,function (index,item) {
                var id = $(item).val();
                var record=window.product_store.getById(id.toString());
                var data = record.data;
                var pro = {
                    id: data.id,
                    title: data.title,
                    typename: data.typename,
                    typeid: data.typeid,
                    litpic: data.litpic,
                    dis: data.typename + '-' + data.title,
                    navid: navid
                };
                productList.push(pro);
            });
            if(productList.length === 0){
                ST.Util.showMsg('请选择产品','5',1000);
                return false;
            }
            res.data = productList;
        }else if(adType === '2'){
            // uni-page
            var pagesObj = $("input[name='uniPagePath']:checked");
            var pagesList = [];
            $.each(pagesObj,function (index,item) {
                var path = $(item).val();
                var title = $(item).attr('data-title');
                var model = $(item).attr('data-model');
                var typeid = $(item).attr('data-typeid');
                var subname = $(item).attr('data-subname');

                var page = {
                    path: path,
                    title:title,
                    dis: model + '-' + title,
                    navid: navid,
                    typeid: typeid,
                    subname: subname
                };
                pagesList.push(page);
            });
            if(pagesList.length === 0){
                ST.Util.showMsg('请选择UNI页面','5',1000);
                return false;
            }
            res.data = pagesList;
        }else if(adType === '3'){
            // 自定义链接
            var linkType = $.trim($("input[name='other_url_type']:checked").val());
            var linkUrl = $.trim($("input[name='link_url']").val());
            var is_nested = $("input[name='is_nested']:checked").val();
            if(!linkUrl && (linkType ==0 ||linkType ==1)){
                ST.Util.showMsg('请填写外部链接地址','5',1000);
                return false;
            }
            var data = {
                path: linkUrl,
                navid: navid,
                is_nested:is_nested
            };

            if(linkType === '0'){//本站链接
                res.adType = 2;
                res.data = [data];
            }else if(linkType === '2'){//电话
                res.adType = 5;
                res.data = [data];
            }else if(linkType === '3'){//企业微信
                res.adType = 6;
                res.data = [data];
            } else{
                res.data = data;
            }
        }else{
            // 三方小程序
            var thirdAppId = $.trim($("input[name='third_appid']").val());
            var thirdPath = $.trim($("input[name='third_path']").val());
            if(!thirdAppId){
                ST.Util.showMsg('请填写三方小程序appid','5',1000);
                return false;
            }
            if(!thirdPath){
                ST.Util.showMsg('请填写三方小程序路径','5',1000);
                return false;
            }
            res.data = {
                appId: thirdAppId,
                path: thirdPath,
                dis: '',
                navid: navid
            };
        }
        ST.Util.responseDialog(res, true);
    });
});
</script>
</html>
<script async type="text/javascript" src="http://update.souxw.com/service/api_V3.ashx?action=releasefeedback&ProductName=stourwebcms&Version=7.1.202103.1101&DomainName=&ServerIP=unknown&SerialNumber=28963355" ></script>
